package cn.wowjoy.pda.android_pharmacy.mvvm.presenter;

import android.support.annotation.NonNull;
import android.util.Log;

import cn.wowjoy.pda.android_pharmacy.common.core.BasePresenter;
import cn.wowjoy.pda.android_pharmacy.mvvm.vm.SettingViewModel;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

import static android.content.ContentValues.TAG;

/**
 * Created by sinyo on 2017/7/16.
 */

public class SettingPresenter extends BasePresenter<SettingViewModel> {
//    private MergeService mMovieService;
    @Override
    public void onCreatePresenter() {
//        mMovieService= (MergeService) ServiceFactory.getInstance().getService(MergeService.class);
    }
//    public String getData(){
////  mMovieService= (MergeService) ServiceFactory.getInstance().getService(MergeService.class);
//        mMovieService.getTopMovie(0, 10)
//                .subscribeOn(Schedulers.io())
//                .observeOn(AndroidSchedulers.mainThread())
//                .subscribe(new DisposableObserver<MovieInfo>() {
//                    @Override
//                    public void onNext(MovieInfo movieInfo) {
//                        binding.rvSetting.setAdapter(new SettingRvAdapter(activity, movieInfo.getSubjects()));
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//
//                    }
//
//                    @Override
//                    public void onComplete() {
//                        Log.e("pxy", "onComplete: " );
//                    }
//                });
//
//    }
    public void go(){
        Observable.create(new ObservableOnSubscribe<Integer>() {
            @Override
            public void subscribe(@NonNull ObservableEmitter<Integer> e) throws Exception {
                Log.e(TAG, "Observable thread is : " + Thread.currentThread().getName());
                e.onNext(1);
                e.onComplete();
            }
        }).subscribeOn(Schedulers.newThread())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .doOnNext(new Consumer<Integer>() {
                    @Override
                    public void accept(@NonNull Integer integer) throws Exception {
                        Log.e(TAG, "After observeOn(mainThread)，Current thread is " + Thread.currentThread().getName());
                    }
                })
                .observeOn(Schedulers.io())
                .subscribe(new Consumer<Integer>() {
                    @Override
                    public void accept(@NonNull Integer integer) throws Exception {
                        Log.e(TAG, "After observeOn(io)，Current thread is " + Thread.currentThread().getName());
                    }
                });
    }
}
